package com.smartboot.plus.wapper;

import com.alibaba.fastjson2.JSONObject;
import com.smartboot.plus.ignite.cache.MqttMetricCache;
import com.smartboot.plus.support.BaseMqttEntityWrapper;
import com.smartboot.plus.vo.MqttEndpointNodeVO;

import static com.smartboot.plus.utils.SystemInfoUtil.formatMemory;


public class EndpointNodeWrapper extends BaseMqttEntityWrapper<MqttMetricCache, MqttEndpointNodeVO> {

    public static EndpointNodeWrapper build() {
        return new EndpointNodeWrapper();
    }


    @Override
    public MqttEndpointNodeVO entityVO(MqttMetricCache entity) {
        if (entity == null) {
            return new MqttEndpointNodeVO();
        }
        MqttEndpointNodeVO mqttEndpointNodeVO = JSONObject.parseObject(entity.getConfig(), MqttEndpointNodeVO.class);
        if (mqttEndpointNodeVO == null) {
            return new MqttEndpointNodeVO();
        }
        String bufferSizeUnit = formatMemory(mqttEndpointNodeVO.getBufferSize());
        mqttEndpointNodeVO.setBufferSizeUnit(bufferSizeUnit);
        String maxPacketSizeUnit = formatMemory(mqttEndpointNodeVO.getMaxPacketSize());
        mqttEndpointNodeVO.setMaxPacketSizeUnit(maxPacketSizeUnit);

        return mqttEndpointNodeVO;

    }
}
